<!-- pass a variable to included page -->
<%@ page import="SSP.*" %>
<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>

<SCRIPT Language="JavaScript">

<%  
   String today = null;
   Today t = new Today();
   today = t.getToday();
   request.setAttribute("picture","Service2");
   request.setAttribute("title", "Create a New Service Order");  
   request.setAttribute("header", "Welcome " + 
   		session.getAttribute("firstname") + " " + 
   		session.getAttribute("lastname") + " from " + 
   		session.getAttribute("customername") + 
   		" : Today is " + today); 
 %>
 

function PM() {
if (form1.servicetype.value == "5") {
location.replace("newso.jsp?equipmentid="+form1.equipmentid.value+
				"&&pm=true"+"&&servicetype="+form1.servicetype.value+
				"&&priority="+form1.priority.value+"&&name="+
				form1.name.value+"&&phone="+form1.phone.value+
				"&&email="+form1.email.value);
}
else {
location.replace("newso.jsp?equipmentid="+form1.equipmentid.value+
				"&&pm=false"+"&&servicetype="+form1.servicetype.value+
				"&&priority="+form1.priority.value+"&&name="+
				form1.name.value+"&&phone="+form1.phone.value+
				"&&email="+form1.email.value);
}
}



</script>

 <%@ include file="header.jsp"%>
 
<TD width="850" vAlign="top">
<br /><h2>Create a New Service Order</h2><br />
<%
String pm = request.getParameter("pm");
int customerid = Integer.parseInt((session.getAttribute("customerid")+ ""));
//int locationid = Integer.parseInt((session.getAttribute("locationid")+ ""));
ResultSet rs = null;
String orderdate = null;
String equipmentid = request.getParameter("equipmentid");
String product = null;
String servicetype = request.getParameter("servicetype");
String priority = request.getParameter("priority");
String name = request.getParameter("name");
String phone= request.getParameter("phone");
String email= request.getParameter("email");

if (name == null){
	name = " ";
}
if (phone == null){
	phone = " ";
}
if (email == null){
	email = " ";
}
if (pm.equals("true")) {
	servicetype = "5";
}

ServiceOrder so = new ServiceOrder();
so.setEquipmentId(Integer.parseInt(equipmentid));
so.setCustomerid(customerid);
product = so.getProduct();

OraDB myDB = new OraDB();
myDB.createConnection();
// sysdate = 2/1/2009
String myQuery = "Select to_char(to_date('2/1/2009','MM/DD/YYYY'), 'MM/DD/YYYY') as orderdate from dual";
rs=myDB.Query(myQuery);
while (rs.next()) {  
   	  orderdate = rs.getString("orderdate");
   	     }
rs.close();
myDB.closeConnection();

 %>
	
<form name=form1 method="post" action=socreate.jsp  onSubmit="return validateform()">
    <table width=100% border=0>
	<tr>
		<td>Customer:</td><td><%=session.getAttribute("customername")%></td>
		<td>Date:</font></td><td><%=orderdate%></td>
	</tr>
	<tr>
		<td>Equipment Number:</font></td><td><%=equipmentid%>
        <input type=hidden name="equipmentid" value=<%=equipmentid%>></td>
        <td>Product:</td><td><%=product%></td>
    </tr>
    <tr>
    	<td>Priority:</td><td><select name="priority">
    <%
	rs = so.getPriority();
	while (rs.next()) {
	if (rs.getString("priorityid").equals(priority)) {
	%>
    	<option value=<%=rs.getString("priorityid")%> Selected><%=rs.getString("prioritydescription")%></option>
  	<%
  	}
  		else {
  	%>
  		<option value=<%=rs.getString("priorityid")%>><%=rs.getString("prioritydescription")%></option>
  	<% 
  	}
  	}
  	rs.close();
  	so.closeConnection(); %>
    </select>&nbsp;<FONT color=#ff0066>*</font></td>
		<td>&nbsp;</td>
    </tr>
    <tr>
    	<td>Service Type:</td>
		<td><select name="servicetype" onChange="PM()">
	<%
		rs = so.getServiceTypes();
		while (rs.next()) {
		if (rs.getString("servicetypeid").equals(servicetype)) {
	%>
		<option value=<%=rs.getString("servicetypeid")%> Selected><%=rs.getString("servicetypedescription")%></option>
	<% 
	}
		else {
	%>
		<option value=<%=rs.getString("servicetypeid")%>><%=rs.getString("servicetypedescription")%></option>
  	<%
  	}
  	}
  	rs.close();
  	so.closeConnection();
  	%>
    	</select>&nbsp;<FONT color=#ff0066>*</font></td>
    <%
    	if (pm.equals("true")) {
	%>
    	<td>Preventive Maintenance Type:</td><td><select name="pm">
    <%
    	rs = so.getPMs();
		while (rs.next()) {
	%>
		<option value=<%=rs.getString("pmid")%>><%=rs.getString("pmdescription")%></option>
  	<%
  	}  %>
  	    </select>
  	<%    
  		rs.close();
  		so.closeConnection();
    }
    	else {
    %>
    	<td>&nbsp;</td>
    	<td>&nbsp;</td>
    <% } %>
    	</tr>
		<tr>
    		<td>Contact Name:</td>
   			<td><input type=text size=25 maxlength=30 name="name" value="<%=name%>"><FONT color=#ff0066>*</font></td>
   			<td>Contact Phone:</td>
        	<td><input type=text size=25 maxlength=15 name="phone" value="<%=phone%>"><FONT color=#ff0066>*</font></td>
        </tr>
        <tr>
    		<td>Contact Email:</td>
   			<td><input type=text size=25 maxlength=30 name="email" value="<%=email%>"><FONT color=#ff0066>*</font></td>
   			<td>&nbsp;</td>
    		<td>&nbsp;</td>
		</tr>
    </table>

<br /><h3>Problem Description:</h3>
    <p><textarea name="problemdescription" rows=5 cols=100></textarea>
    </p>
	<input type=submit value="Create New Service Order" name=submit>
	<input type=reset name=reset Value=Reset>
</form>


	<p><FONT color=#ff0066>*</font> <font size=2>Denotes a required field</font></p>

</TABLE>
</TD></TR></TABLE></BODY>




<script Language=JavaScript>
function validateform() 
{
  

 if (form1.name.value == "" || form1.name.value == " ")  
 {
 alert("Contact Name cannot be left blank.");  
 return false;   }
 
 if (form1.phone.value == "" || form1.phone.value == " " || (isNaN(form1.phone.value))) 
 {
    alert("Contact Phone cannot be alphanumeric or left blank");
    return false;   }  
    
    if (form1.email.value == "" || form1.email.value == " ") {  
 alert("Contact Email cannot be left blank."); 
 return false;   } 
 
 if
(confirm("Are you sure you want to update?")==false) 
{
return false; 
}
}

</SCRIPT>

</HTML>
